import json
import random

import tools
import pytest
print('good')
"""
写点注释
"""
name = "goods"
age = 18
print(name, age)
print(age, type(age))
num = '175.5'
num_1 = float(num)
num_2 = int(num_1)
print(num_2, type(num_2))
print('姓名 {}， 年龄{}， 身高{}'.format(name, age, num_1), end='\n')
print('姓名 {}， 年龄{}， 身高{}'.format(name, age, num_1), end='\t')
print(f'姓名 {name}， 年龄{age}， 身高{num_1}')
a = 1001
b = 1002
print(a // b)
print(a / b)
if a > b:
    print(a - b)
elif a == b:
    print(b - a)
else:
    print("xxx")

i = 1
while i <= 5:
    print('i={}'.format(i))
    i += 1

while True:
    rand = random.randint(1, 5)
    if rand >= 1:
        break

for i in 'good':
    print(i)

s = 0
for i in range(51):
    s += i

print(s)

str1 = 'abcdefg'
print(str1[0])
print(str1[-2])
print(str1[-5] * 30)

i = 0
while i < len(str1):
    print(str1[i] * 2)
    i += 1

print(str1[0:3:1])
print(str1[:4:1])
print(str1[:4:2])

print(str1[4:7])
print(str1[1:-1:2])

find = str1.find('c')
print(find)

str2 = str1.replace('b', 't')
print(str2)

str3 = 's1 s2 s3 s4 s5'
result = str3.split(' ')
print(type(result))
for i in result:
    print(i)

str4 = ',,'.join(result)
print(str4)

list_1 = list('love')
print(list_1)

list_2 = ['nning', 'xx', 'xxx', 'xxxx', 'gg']
print(list_2)

print(list_2[:2])
list_2.append(1)
list_2.pop(2)  # 按位置删除
print(list_2.count(1))
list_2.reverse()
list_3 = list_2[::-1]
print(list_2)
print(list_3)
list_4 = [list_3, list_2]
print(list_4)
print(list_4[0][0])

tuple1 = (1, 2, 3)
tuple2 = tuple('love')
tuple3 = ('love',)
print(tuple1, type(tuple1))
print(tuple2, type(tuple2))
print(tuple3, type(tuple3))
a, b, c, d = tuple2  # 拆包
print(a, b, c, d)

dict_1 = {1: 'good', 2: 'seed'}
dict_2 = {'小明': 'good', '小强': 'seed'}
print(dict_1)
print(dict_2)
print(dict_2.values())
print(dict_2.get('小明'))
dict_2['小孙'] = 'peek'
print(dict_2)
dict_2['小孙'] = 'seek'
print(dict_2)
dict_2.pop('小明')
print(dict_2)
dict_2['宁宁'] = ['ookk', 'iiuu', 'sskk']
print(dict_2)
dict_2['宁宁'].append('ffmm')
print(dict_2)
print(dict_2['宁宁'])
for i in dict_2:
    print(i)
print(dict_2.keys())
print(dict_2.values())
for i in dict_2.values():
    print(i)
    aa = tuple(i)
print('//////')
print(aa)
for i, j in dict_2.items():
    print(i, j)

list_5 = [1, 2, 3, 4, 5, 1, 2, 1, 1, 's', 's', 'd']
print(list(set(list_5)))  # 列表去重 使用set
print(1 in list_5)


def printall():
    """打印 1 2 """
    print(1)
    print(2)


printall()

import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
import numpy as np
import matplotlib.dates as mdates
from datetime import datetime, timedelta

import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
import numpy as np
import matplotlib.dates as mdates
from datetime import datetime, timedelta

# 设置支持中文的字体
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号





# 调用函数
plot_time_series()


# 调用函数

def sum_2_nums(a, b):
    c = a + b
    return c


print(sum_2_nums(2, 5), type((sum_2_nums(2, 5),)))

print(tools.sum_sum(10, 20))
sss = 10
print(id(sss))
print(sss)
ssd = sss
ssd = 999
print(sss)
ssss = [1, 2, 33]

dddd = ssss
dddd[0] = 9  # 列表是存储地址，对其修改时会修改对应地址的内容
print(ssss)
ssss = [5, 5, 5]  # 若左侧为列表整体，则会修改新的地址
print(dddd)
print(ssss)

print(tuple1)


# list 的append 和 pop是全局操作


def sums_sum(*args):
    sum = 0
    for i in args:
        sum = sum + i
    return sum, sum + 1  # 返回多个数据值


print(sums_sum(10, 20, 0, 50, 90))
print(sums_sum(*ssss))  # 函数传参过程中的拆包


class Pokemon:
    def __init__(self, name, power, level):
        self.name = name
        self.power = power
        self.level = level

    def printname(self):
        print(self.name)

    def printpower(self):
        print(self.power)

    def printlevel(self):
        print(self.level)

    def __str__(self):
        return f"{self.name}, {self.power}, {self.level}"


pukachu = Pokemon('pikaqiu', 'shishi', '5')
pukachu.printpower()
print(pukachu)


class Person:
    def __init__(self, name, weight):
        self.name = name
        self.weight = weight

    def running(self):
        self.weight = self.weight - 0.5

    def eating(self):
        self.weight = self.weight + 1

    def __str__(self):
        return f"{self.weight}"


xiaoming = Person('小明', 75)
xiaoming.running()
print(xiaoming)
xiaoming.eating()
print(xiaoming)


class Houseitem:
    count = 0

    def __init__(self, item_name, sqar):
        self.item_name = item_name
        self.sqar = sqar
        Houseitem.count += 1


class good_items(Houseitem):
    def __init__(self, name, sqar, station):
        super().__init__(name, sqar)
        self.station = station

    def __str__(self):
        return f"{self.item_name},{self.sqar},{self.station}"


class home:
    def __init__(self, style, sqar):
        self.style = style
        self.__sqar = sqar  # 名称前加__会使数据变为私有 可以设定set方法进行内容修改
        self.houseitem_all = list()
        self.left_sqar = sqar

    def add_item(self, houseitem):
        if houseitem.sqar > self.left_sqar:
            print('添加失败')
        else:
            self.left_sqar = self.left_sqar - houseitem.sqar
            self.houseitem_all.append(houseitem.item_name)
            print('成功')

    def __str__(self):
        return f"{self.left_sqar} {self.houseitem_all}"


bed = Houseitem('bed', 4)
table = Houseitem('table', 2)
chest = Houseitem('chest', 2.5)
nnings = home('大床房', 50)
print(nnings)
nnings.add_item(bed)
print(nnings)
nnings.add_item(table)
print(nnings)
nnings.add_item(chest)
print(nnings)

good_items1 = good_items('bed', 5, 'good')
print(good_items1)

print(good_items1.count)


# 静态方法（@staticmethod）适用于不需要访问类或实例状态的情况。
# 它们通常作为工具函数存在，提供与类相关的通用功能。
# 使用静态方法可以提高代码的组织性和可读性，同时避免不必要的实例化。

# 实例方法是对上级的修改或者调用
class ClassRoom:
    # 类属性
    class_name = "高一班"
    class_all = list()

    def __init__(self, student_name):
        # 实例属性
        self.student_name = student_name

    @classmethod
    def add_student(cls, student_name):
        # 类方法，用于向班级中添加学生
        cls.class_all.append(student_name)
        print(f"学生 {student_name} 加入了 {cls.class_name}")
        return cls(student_name)

    @classmethod
    def change_class_name(cls, new_name):
        # 类方法，用于修改班级名称
        cls.class_name = new_name
        print(f"班级名称已更改为：{new_name}")

    @staticmethod
    def show_what_can_i_do():
        return "显示班级和人员"


# 调用类方法
ClassRoom.change_class_name("高二班")  # 输出：班级名称已更改为：高二班

# 创建实例
student1 = ClassRoom.add_student("张三")  # 输出：学生 张三 加入了 高二班
student2 = ClassRoom.add_student("李四")  # 输出：学生 李四 加入了 高二班

# 打印实例属性
print(student1.student_name)  # 输出：张三
print(student2.student_name)  # 输出：李四

print(student1.class_all)  # 查看全班名字
print(student1.show_what_can_i_do())

f = open('a.txt', 'w', encoding='utf-8')

f.write('good\n')
f.write('ssod\n')

f.close()

with open('a.txt', 'a', encoding='utf-8') as f:
    f.write('seed')

with open('a.txt', 'r', encoding='utf-8') as f:
    result = f.readline()
    print(result, end='')
    while result != '':
        result = f.readline()
        print(result, end='')
    print('\n')
    print('*' * 30)

with open('a.txt', 'r', encoding='utf-8') as f:
    for i in f:
        print(i, end='\n')
info = {
    'name': 'nning',
    'age': '24',
    'info': {
        'expr': '2',  # 工作年限
        'depart': '技术部'  # 部门
    }
}

print(info)
with open('b.json', 'w', encoding='utf-8') as f:
    json.dump(info, f, ensure_ascii=False, indent=2)

with open('b.json', 'r', encoding='utf-8') as f:
    result: dict = json.load(f)
    print(result.get("name"))
    print(result.get("age"))
    print(result.get("info"))

try:
    num = int(input("输入一个被除数"))
    num1 = int(input("输入一个除数"))
    num2 = (num / num1)
except Exception as e:
    print("出现异常", e)
else:
    print(num2)
finally:
    print("结束")


def set_password():
    password = input("输入八位密码")
    if len(password) == 8:
        print("输入成功")
    else:
        raise Exception("密码必须为八位")


#set_password()

print(tuple(info.values()))